home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgramD2.iso / Borland / Borland C++ V5.02 / SRCBDTO.PAK / TABLE.CPP < prev    next >
Text File  |  1997-05-06  |  8KB  |  449 lines

  1. //-----------------------------------------------------------------------------
  2. // Visual Database Tools
  3. // Copyright (c) 1996 by Borland International, All Rights Reserved
  4. //
  5. // table.cpp
  6. // TTable wrapper class
  7. //-----------------------------------------------------------------------------
  8.  
  9. #include <vdbt\bdto.h>
  10.  
  11. #pragma hdrstop
  12.  
  13. #include "wrapit.h"
  14. #include "misc.h"
  15.  
  16. //-----------------------------------------------------------------------------
  17.  
  18. void TTable::SetTTable( PIUnknown p )
  19. {
  20.     table = 0;
  21.     if (p)
  22.         p->QueryInterface( IID_ITTable, (void**) &table );
  23. }
  24.  
  25. void TTable::ClearTTable( void )
  26. {
  27.     if (table)
  28.     {
  29.         table->Release();
  30.         table = 0;
  31.     }
  32. }
  33.  
  34. TTable::TTable( void ) : TDBDataSet()
  35. {
  36.     table = CreateITTable();
  37.     TDBDataSet::SetPIT( table );
  38. }
  39.  
  40. TTable::TTable( PITTable p ) : TDBDataSet( p )
  41. {
  42.     SetTTable( p );
  43. }
  44.  
  45. TTable::TTable( const TTable& p ) : TDBDataSet( p )
  46. {
  47.     SetTTable( p.table );
  48. }
  49.  
  50. TTable::TTable( PTTable p ) : TDBDataSet( p )
  51. {
  52.     SetTTable( p ? p->table : 0 );
  53. }
  54.  
  55. TTable::TTable( HWND hdlg, int idc ) : TDBDataSet()
  56. {
  57.     SetTTable( GetVBXPIUnknown( hdlg, idc ) );
  58.     TDBDataSet::SetPIT( table );
  59. }
  60.  
  61. void TTable::AttachToControl( HWND hdlg, int idc )
  62. {
  63.     SetPIT( GetVBXPIUnknown( hdlg, idc ) );
  64. }
  65.  
  66. void TTable::AttachControl( HWND hdlg, int idc )
  67. {
  68.     SetVBXPIUnknown( hdlg, idc, table );
  69. }
  70.  
  71. TTable& TTable::operator=( PITTable p )
  72. {
  73.     TDBDataSet::operator=(p);
  74.     ClearTTable();
  75.     SetTTable( p );
  76.     return *this;
  77. }
  78.  
  79. TTable& TTable::operator=( const TTable& p )
  80. {
  81.     if (this != &p)
  82.     {
  83.         TDBDataSet::operator=(p);
  84.         ClearTTable();
  85.         SetTTable( p.table );
  86.     }
  87.     return *this;
  88. }
  89.  
  90. int TTable::operator==( const TTable& p ) const
  91. {
  92.     if (this == &p)
  93.         return true;
  94.     if (table == p.table)
  95.         return true;
  96.     return false;
  97. }
  98.  
  99. int TTable::operator!=( const TTable& p ) const
  100. {
  101.     return ! operator==(p);
  102. }
  103.  
  104. TTable::~TTable()
  105. {
  106.     ClearTTable();
  107. }
  108.  
  109. void TTable::SetPIT( PIUnknown p )
  110. {
  111.     ClearTTable();
  112.     SetTTable( p );
  113.     TDBDataSet::SetPIT( p );
  114. }
  115.  
  116. int32 TTable::BatchMove( TDataSet& pt, TBatchMode m )
  117. {
  118.     if (table)
  119.         return table->BatchMove( pt.GetPITDataSet(), m );
  120.     return 0;
  121. }
  122.  
  123. void TTable::AddIndex( const string& name, const string& fields, TIndexOptions options )
  124. {
  125.     if (table)
  126.         table->AddIndex( AnyString(name).GetPITAnyString(), AnyString(fields).GetPITAnyString(), options );
  127. }
  128.  
  129. void TTable::ApplyRange( void )
  130. {
  131.     if (table)
  132.         table->ApplyRange();
  133. }
  134.  
  135. void TTable::CancelRange( void )
  136. {
  137.     if (table)
  138.         table->CancelRange();
  139. }
  140.  
  141. void TTable::CreateTable( void )
  142. {
  143.     if (table)
  144.         table->CreateTable();
  145. }
  146.  
  147. void TTable::DeleteIndex( const string& n )
  148. {
  149.     if (table)
  150.         table->DeleteIndex( AnyString(n).GetPITAnyString() );
  151. }
  152.  
  153. void TTable::DeleteTable( void )
  154. {
  155.     if (table)
  156.         table->DeleteTable();
  157. }
  158.  
  159. void TTable::EditKey( void )
  160. {
  161.     if (table)
  162.         table->EditKey();
  163. }
  164.  
  165. void TTable::EditRangeEnd( void )
  166. {
  167.     if (table)
  168.         table->EditRangeEnd();
  169. }
  170.  
  171. void TTable::EditRangeStart( void )
  172. {
  173.     if (table)
  174.         table->EditRangeStart();
  175. }
  176.  
  177. void TTable::EmptyTable( void )
  178. {
  179.     if (table)
  180.         table->EmptyTable();
  181. }
  182.  
  183. bool TTable::FindKey( TVarRecs& values )
  184. {
  185.     if (table)
  186.         return MakeBool( table->FindKey( values.Count, values.Variants ) );
  187.     return false;
  188. }
  189.  
  190. void TTable::FindNearest( TVarRecs& values )
  191. {
  192.     if (table)
  193.         table->FindNearest( values.Count, values.Variants );
  194. }
  195.  
  196. void TTable::GetIndexNames( TStrings& list )
  197. {
  198.     if (table)
  199.         table->GetIndexNames( list.GetPITStrings() );
  200. }
  201.  
  202. void TTable::GotoCurrent( TTable& pt )
  203. {
  204.     if (table)
  205.         table->GotoCurrent( pt.table );
  206. }
  207.  
  208. bool TTable::GotoKey( void )
  209. {
  210.     if (table)
  211.         return MakeBool( table->GotoKey() );
  212.     return false;
  213. }
  214.  
  215. void TTable::GotoNearest( void )
  216. {
  217.     if (table)
  218.         table->GotoNearest();
  219. }
  220.  
  221. void TTable::LockTable( TLockType t )
  222. {
  223.     if (table)
  224.         table->LockTable( t );
  225. }
  226.  
  227. void TTable::RenameTable( const string& newname )
  228. {
  229.     if (table)
  230.         table->RenameTable( AnyString(newname).GetPITAnyString() );
  231. }
  232.  
  233. void TTable::SetKey( void )
  234. {
  235.     if (table)
  236.         table->SetKey();
  237. }
  238.  
  239. void TTable::SetRange( TVarRecs& startValues, TVarRecs& endValues )
  240. {
  241.     if (table)
  242.         table->SetRange( startValues.Count, startValues.Variants, endValues.Count, endValues.Variants );
  243. }
  244.  
  245. void TTable::SetRangeEnd( void )
  246. {
  247.     if (table)
  248.         table->SetRangeEnd();
  249. }
  250.  
  251. void TTable::SetRangeStart( void )
  252. {
  253.     if (table)
  254.         table->SetRangeStart();
  255. }
  256.  
  257. void TTable::UnlockTable( TLockType t )
  258. {
  259.     if (table)
  260.         table->UnlockTable( t );
  261. }
  262.  
  263. DEFINE_BDTO_OBJECTPROP_RO_FAST( TTable, TIndexDefs, PITIndexDefs, IndexDefs );
  264. DEFINE_BDTO_PROP_RO( TTable, int, IndexFieldCount );
  265. DEFINE_BDTO_ARRAYOBJECTPROP_RO_FAST( TTable, TField, PITField, IndexFields, int );
  266. DEFINE_BDTO_PROP_RW( TTable, bool, KeyExclusive );
  267. DEFINE_BDTO_PROP_RW( TTable, int, KeyFieldCount );
  268.  
  269. void TTable::GetIndexDefs( TIndexDefs& i )
  270. {
  271.     if (table)
  272.     {
  273.         PITIndexDefs pit = table->get_IndexDefs();
  274.         if (pit)
  275.         {
  276.             i.SetPIT( pit );
  277.             pit->Release();
  278.         }
  279.     }
  280. }
  281.  
  282. void TTable::GetIndexFieldCount( int& c )
  283. {
  284.     if (table)
  285.         c = table->get_IndexFieldCount();
  286. }
  287.  
  288. void TTable::GetIndexFields( int i, TField& f )
  289. {
  290.     if (table)
  291.     {
  292.         PITField pit = table->get_IndexFields( i );
  293.         if (pit)
  294.         {
  295.             f.SetPIT( pit );
  296.             pit->Release();
  297.         }
  298.     }
  299. }
  300.  
  301. void TTable::GetKeyExclusive( bool& k )
  302. {
  303.     if (table)
  304.         k = MakeBool( table->get_KeyExclusive() );
  305. }
  306.  
  307. void TTable::SetKeyExclusive( bool k )
  308. {
  309.     if (table)
  310.         table->put_KeyExclusive( MakeVariantBool( k ) );
  311. }
  312.  
  313. void TTable::GetKeyFieldCount( int& c )
  314. {
  315.     if (table)
  316.         c = table->get_KeyFieldCount();
  317. }
  318.  
  319. void TTable::SetKeyFieldCount( int c )
  320. {
  321.     if (table)
  322.         table->put_KeyFieldCount( c );
  323. }
  324.  
  325. DEFINE_BDTO_PROP_RW( TTable, bool, Exclusive );
  326. DEFINE_BDTO_OBJECTPROP_RW( TTable, string, IndexFieldNames );
  327. DEFINE_BDTO_OBJECTPROP_RW( TTable, string, IndexName );
  328. DEFINE_BDTO_OBJECTPROP_RW( TTable, string, MasterFields );
  329. DEFINE_BDTO_OBJECTPROP_RW_FAST( TTable, TDataSource, PITDataSource, MasterSource );
  330. DEFINE_BDTO_PROP_RW( TTable, bool, ReadOnly );
  331. DEFINE_BDTO_OBJECTPROP_RW( TTable, string, TableName );
  332. DEFINE_BDTO_PROP_RW( TTable, TTableType, TableType );
  333. DEFINE_BDTO_PROP_RW( TTable, TUpdateMode, UpdateMode );
  334.  
  335. void TTable::GetExclusive( bool& e )
  336. {
  337.     if (table)
  338.         e = MakeBool( table->get_Exclusive() );
  339. }
  340.  
  341. void TTable::SetExclusive( bool e )
  342. {
  343.     if (table)
  344.         table->put_Exclusive( MakeVariantBool( e ) );
  345. }
  346.  
  347. void TTable::GetIndexFieldNames( string& s )
  348. {
  349.     if (table)
  350.         AnyString( table->get_IndexFieldNames() ).GetString( s );
  351. }
  352.  
  353. void TTable::SetIndexFieldNames( const string& n )
  354. {
  355.     if (table)
  356.         table->put_IndexFieldNames( AnyString(n).GetPITAnyString() );
  357. }
  358.  
  359. void TTable::GetIndexName( string& s )
  360. {
  361.     if (table)
  362.         AnyString( table->get_IndexName() ).GetString( s );
  363. }
  364.  
  365. void TTable::SetIndexName( const string& n )
  366. {
  367.     if (table)
  368.         table->put_IndexName( AnyString(n).GetPITAnyString() );
  369. }
  370.  
  371. void TTable::GetMasterFields( string& s )
  372. {
  373.     if (table)
  374.         AnyString( table->get_MasterFields() ).GetString( s );
  375. }
  376.  
  377. void TTable::SetMasterFields( const string& m )
  378. {
  379.     if (table)
  380.         table->put_MasterFields( AnyString(m).GetPITAnyString() );
  381. }
  382.  
  383. void TTable::GetMasterSource( TDataSource& d )
  384. {
  385.     if (table)
  386.     {
  387.         PITDataSource pit = table->get_MasterSource();
  388.         if (pit)
  389.         {
  390.             d.SetPIT( pit );
  391.             pit->Release();
  392.         }
  393.     }
  394. }
  395.  
  396. void TTable::SetMasterSource( const TDataSource& source )
  397. {
  398.     if (table)
  399.         table->put_MasterSource( source.GetPITDataSource() );
  400. }
  401.  
  402. void TTable::GetReadOnly( bool& r )
  403. {
  404.     if (table)
  405.         r = MakeBool( table->get_ReadOnly() );
  406. }
  407.  
  408. void TTable::SetReadOnly( bool r )
  409. {
  410.     if (table)
  411.         table->put_ReadOnly( MakeVariantBool( r ) );
  412. }
  413.  
  414. void TTable::GetTableName( string& s )
  415. {
  416.     if (table)
  417.         AnyString( table->get_TableName() ).GetString( s );
  418. }
  419.  
  420. void TTable::SetTableName( const string& n )
  421. {
  422.     if (table)
  423.         table->put_TableName( AnyString(n).GetPITAnyString() );
  424. }
  425.  
  426. void TTable::GetTableType( TTableType& t )
  427. {
  428.     if (table)
  429.         t = table->get_TableType();
  430. }
  431.  
  432. void TTable::SetTableType( TTableType t )
  433. {
  434.     if (table)
  435.         table->put_TableType( t );
  436. }
  437.  
  438. void TTable::GetUpdateMode( TUpdateMode& u )
  439. {
  440.     if (table)
  441.         u = table->get_UpdateMode();
  442. }
  443.  
  444. void TTable::SetUpdateMode( TUpdateMode u )
  445. {
  446.     if (table)
  447.         table->put_UpdateMode( u );
  448. }
  449.